package com.lingyu.jsjx.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lingyu.jsjx.mapper.DocumentShareMapper;
import com.lingyu.jsjx.domain.DocumentShare;
import com.lingyu.jsjx.service.IDocumentShareService;
import org.springframework.util.CollectionUtils;

/**
 * 共享
Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@Service
public class DocumentShareServiceImpl extends ServiceImpl<DocumentShareMapper, DocumentShare> implements IDocumentShareService
{
    @Autowired
    private DocumentShareMapper documentShareMapper;

    @Override
    public List<DocumentShare> selectDocumentShareByWordId(Long wordId) {
        return documentShareMapper.selectDocumentShareByWordId(wordId);
    }

    /**
     * 查询共享
列表
     * 
     * @param documentShare 共享

     * @return 共享

     */
    @Override
    public List<DocumentShare> selectDocumentShareList(DocumentShare documentShare)
    {
        return documentShareMapper.selectDocumentShareList(documentShare);
    }

    /**
     * 新增共享

     * 
     * @param documentShare 共享

     * @return 结果
     */
    @Override
    public int insertDocumentShare(DocumentShare documentShare)
    {
        documentShare.setCreateTime(DateUtils.getNowDate());
        return documentShareMapper.insertDocumentShare(documentShare);
    }

    /**
     * 新增共享

     *
     * @param list 共享

     * @return 结果
     */
    @Override
    public int batchInsertDocumentShare(List<DocumentShare> list)
    {
        if (CollectionUtils.isEmpty(list)) {
            return 0;
        }
        // 分批次处理，避免SQL过长
        int batchSize = 500;
        int total = 0;
        for (int i = 0; i < list.size(); i += batchSize) {
            int end = Math.min(i + batchSize, list.size());
            List<DocumentShare> subList = list.subList(i, end);
            total += documentShareMapper.batchInsertDocumentShare(subList);
        }
        return total == list.size() ? 1 : 0;
    }


    /**
     * 批量删除共享

     * 
     * @param shareIds 需要删除的共享
主键
     * @return 结果
     */
    @Override
    public int deleteDocumentShareByShareIds(Long[] shareIds)
    {
        return documentShareMapper.deleteDocumentShareByShareIds(shareIds);
    }

    /**
     * 删除共享
信息
     * 
     * @param shareId 共享
主键
     * @return 结果
     */
    @Override
    public int deleteDocumentShareByShareId(Long shareId)
    {
        return documentShareMapper.deleteDocumentShareByShareId(shareId);
    }
}
